#include "serialman.h"



void SerialManager::CycelTx(void) {
    m_serial_inc->write((*iter));
    qDebug() << "cycel tiggered: " << (*iter);

    iter++;
    if (iter == txque->end()) {
        iter = txque->begin();
    }
}
void SerialManager::AddMessage(const QByteArray& msg) {
    /* TODO : reinit iterator */
    txque->push_back(msg);
}
void SerialManager::ClearAndAddMessage(const QByteArray& msg) {
    txque->clear();
    txque->push_back(msg);
    iter = txque->begin();
}

void SerialManager::SingleTx(const QByteArray& msg) {
    m_serial_inc->write(msg);
}

SerialManager::SerialManager()
{
    txque = new QByteArrayList;
    m_serial_inc = new QSerialPort;

    m_serial_inc->setParity(QSerialPort::NoParity);
    m_serial_inc->setDataBits(QSerialPort::Data8);
    m_serial_inc->setStopBits(QSerialPort::OneStop);
}
SerialManager::~SerialManager() {
    delete txque;
}

QSerialPort* SerialManager::Instance()
{
    return m_serial_inc;
}
